<?php
session_start();
include_once 'functions/function.php';
include_once 'functions/newForum.class.php';

$Db = Db();


if(!isset($_SESSION['id'])){
    
     
    session_start();
    session_unset();
    session_destroy();

    header('Location: index.php');
}


if(isset($_POST['title'])){
    
    
    $newForum = new newForum($_POST['title'],$_POST['group']);
   
   $error = $newForum->check();
    
    if($error == "ok"){
        
        if($newForum->add()){
           
            header('Location: home.php?forumTitle='.$_POST['title']);
        }
        else{
            
            $error = "Sorry, There was a problem adding your Forum";
            $display = $error;
            
           
        }
        
    }
    else{
        
        $display = $error;
        
    }
    
}


?>

 



<!DOCTYPE html>
<html>
    <head>
		<link rel="stylesheet" href="css/newForum.css">
	</head >
	
	
	<body style="background: url(images/background.jpg);">
	
	
		<div id="wrapper">
		
			<div id="head">
		
					<table id="myTable" border=0>
						<tr>
							<td class="leftCell" ><span>Hello!! <span class="newAccount"><?php echo $_SESSION['username']; ?></a></span></td>
							<td class="middleCell" ><a class="newAccount" href="home.php">Home</a></td>
							<td class="rightCell" ><span><a class="newAccount" href="logOut.php">Sign out</a></span></td>
						</tr>
					</table>
		
            </div>
	
		<div id="container">
		
		
			<div id="optionSection">
			
                            <p class="newForum"><a class="noDecoration3" href="newForum.php">Create a New Forum</a></p>
			
			</div>
		
			
			
			<div id="myTable2">
			
				<div id="postSection">
				
				
					<fieldset>
					<legend class="legend">Create New Forum</legend>
				
                                        <form method="post" action="newForum.php">
						
						
							
							    <p class="subject"><input  type="text" name="title" placeholder="Forum name" size="40"/></p>
						
							
                                                                    <p class="subject"><span class="forumType"><label>Forum Type</label></span>
                                                                        
                                                                        <span>
                                                                              <select name="group">
                                                                                    <option value="f">Public</option>
                                                                                    <option value="t">Private</option>
                                                                                </select>
                                                                       </span>   
                                                                    </p>
   							   <p class="submitAlign"><input id="submit" type="submit" value="Create"/></p>
					</form>
				
					</fieldset>
                                    
                                        <p id="error">
                                               
                                                 <?php
                                                
                                                if(isset($display)){
                                                    
                                                    echo $display;
                                                }
                                                
                                                ?>
                                                
                                                
                                            </p>
					
				</div>
				
			</div>
	
			
	
		</div>
		
		</div>
		
		
	
	</body>
</html>
          
